# 和谐数组是指一个数组里元素的最大值和最小值之间的差别 正好是 1 。
# nums = [1,3,2,2,5,2,3,7]
nums = [1,2,2,3,4,5,1,1,1,1]

# nums.sort()
# begin, max_num = 0,0
# for end in range(len(nums)):
#     while nums[end] - nums[begin] > 1:
#         begin += 1
#     if nums[end] - nums[begin] == 1 and (end-begin+1) > max_num:
#         max_num = end-begin+1

# print(max_num)

import collections

nums = collections.Counter(nums)
max_num = 0
for i, v in nums.items():
    if i+1 in nums and max_num < v + nums[i+1]:
        max_num = v + nums[i+1]
print(max_num)